/**
* Class representing a single instance of a message published to, or subscribed to, by a plugin component
*/
jsx3.lang.Class.defineClass("ux.core.util.component.Message",
        jsx3.lang.Object,
        null,
        function(config) {

            /**
            * The subject of the message
            * @private
            */
            config.prototype.subject = null;

            /**
            * Description of the message
            * @private
            */
            config.prototype.description = null;

            /**
            * {jsx3.util.List} List of {ux.core.util.component.Param} objects representing the parameters of the
            * message
            * @private
            */
            config.prototype.params = null;

            /**
             * Constructor for this class.
             *
             * @param doc {jsx3.xml.Entity} an xml node containing the information for a published or subscribed message
             * @throws {ux.core.exception.InvalidComponentSchemaException} if the xml is invalid
             */
            config.prototype.init = function(doc) {
                this.jsxsuper();
                this.params = new jsx3.util.List(0);
                var children = doc.getChildNodes().iterator();
                while(children.hasNext()) {
                    var child = children.next();
                    var childName = child.getNodeName();
                    if(childName == "subject") {
                        this.subject = child.getValue();
                    }
                    else if(childName == "description") {
                        this.description = child.getValue();
                    }
                    else if(childName == "params") {
                        var childParams = child.getChildNodes().iterator();
                        while(childParams.hasNext()) {
                            var childParam = childParams.next();
                            if(childParam.getNodeName() == "param") {
                                this.params.add(new ux.core.util.component.Param(childParam), this.params.size());
                            }
                        }
                    }
                }
            }

            /**
            * Returns the subject of this Message.
            *
            * @return {String} the subject of this Message
            */
            config.prototype.getSubject = function() {
                return this.subject;
            }

            /**
            * Returns the description of this Message.
            *
            * @return {String} the description of this Message
            */
            config.prototype.getDescription = function() {
                return this.subject;
            }

            /**
            * Returns an iterator of the Params for this Message.
            *
            * @return {jsx3.util.Iterator} an iterator of the Params {ux.core.util.component.Param} for this Message
            */
            config.prototype.getParams = function() {
                return this.params.clone().iterator();
            }

            /**
            * Returns a string representing this object in the xml format specified by the component.xsd schema
            *
            * @param prepend {String} a string to be prepended to each line of the returned XML (useful for indenting)
            *
            * @returns {String} this ComponentConfig as XML, as specified by the component.xsd schema
            */
            config.prototype.toString = function(prepend) {
                if(!prepend) {
                    prepend + "";
                }
                var ret = prepend + "<message>\n";
                if(this.description) {
                    ret += prepend + "   <description>" + this.description + "</description>\n";
                }
                if(this.id) {
                    ret += prepend + "   <subject>" + this.subject + "</subject>\n";
                }
                if(this.params.size() > 0) {
                    ret += prepend + "   <params>\n";
                    var iter = this.params.iterator();
                    while(iter.hasNext()) {
                        ret += iter.next().toString(prepend + "      ");
                    }
                    ret += prepend + "   </params>\n";
                }
                ret += prepend + "</message>\n";
                return ret;
            }
        }
);